import numpy as np
import cmath
import matplotlib.pyplot as plt
import sys

sys.path.append('G:/workspace/idea/badminton/src/test/resources/matplotlib/navigation')
from Vector3D import Vector3D

# 输入基本参数=====================================================================
# 初始站位
start = Vector3D(305, 335, 900, 1)
# 速度大小
v = 13.6944# v = 0.911079
# 速度方向
velocity=Vector3D(0, 2, 1, 1)
# =============================================================================

velocity.l=v
speed = velocity.velocity_decomposition()

g = 0.00098
G = 9.8

vx = speed.x
vy = speed.y
vz = speed.z

a = -g / 2
b = vz
c = start.z

d = (b ** 2) - (4 * a * c)
sol1 = (-b - cmath.sqrt(d)) / (2 * a)
sol2 = (-b + cmath.sqrt(d)) / (2 * a)
t = sol1
nt = np.linspace(0, t, 10)

C = 1.29
P = 0.2
S = 27 * np.pi * 1e-4
M = 5 / 1e+3

F重力 = M * G
F空气阻力 = 0.5 * C * P * S * v ** 2
# aAll公式调整=============================================================================
# 空气阻力转为cm/ms^2的加速度 最大0.004104113482229271
# aAll = F空气阻力 * 1e-4 / M

# 结合v/t时间图反推 2024年3月14日
V变= -0.080537*nt + 13.449977
aAll=0.080537

# 阻力/10
# aAll = F空气阻力 * 1e-5 / M

# 阻力和时间反比
# aAll = F空气阻力 * 1e-4 / (M*nt)

# 阻力和时间反比,函数
# aAll = F空气阻力 * 1e-4 / M*np.sqrt(nt)

# 阻力和时间反比,函数
# aAll =1/ nt
# aAll =0.08-F空气阻力 * 1e-4 / M*np.sqrt(nt)
# aAll =F空气阻力 * 1e-4 *200/ (M*((nt+200)))
# aAll0 =F空气阻力 * 1e-4 *200/ (M*((0+200)))

# aAll =F空气阻力 * 1e-4 / (M*np.sqrt(nt+20))
# aAll0 =F空气阻力 * 1e-4/ (M*np.sqrt(0+20))

# aAll =1/ nt**2

# 使用极限函数进行公式设计(0.1,0.4),(100,0.1)
# aAll =F空气阻力 * 1e-4*5.4772 / (M*np.sqrt(nt/120+30))
# aAll0 =F空气阻力 * 1e-4*5.4772/ (M*np.sqrt(0/120+30))
# aAll =4e-5 * nt ** 2 - 8e-3 * nt + 0.4+1e-5
# =============================================================================

velocity.l=aAll
aAllA = velocity.velocity_decomposition()

ax = aAllA.x
ay = aAllA.y
az = aAllA.z

nx = start.x + vx * nt - 0.5 * ax * nt ** 2
ny = start.y + vy * nt - 0.5 * ay * nt ** 2
nz = start.z + vz * nt - 0.5 * (g - az) * nt ** 2

# manager = plt.subplot(projection='3d')  # 创建一个三维的绘图工程
# manager.set_title('3d_image_show')  # 设置本图名称
# manager.scatter(nx, ny, nz, c='r')  # 绘制数据点 c: 'r'红色，'y'黄色，等颜色

# manager.set_xlabel('X')  # 设置x坐标轴
# manager.set_ylabel('Y')  # 设置y坐标轴
# manager.set_zlabel('Z')  # 设置z坐标轴

# plt.plot(nt, ax)
# plt.plot(nt, ay)
# plt.plot(nt, az)
# plt.plot(nt, aAll)
# plt.plot(ny, nz)
plt.show()
